package com.mayisoftware.mayioa.business.statistic.impl.controller;

import com.mayisoftware.mayioa.business.statistic.api.domain.*;
import com.mayisoftware.mayioa.business.statistic.api.service.IStatisticService;
import com.mayisoftware.mayioa.platform.impl.util.ShiroUtils;
import com.mayisoftware.mayioa.platform.impl.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

/**
 * 骨干统计控制器
 */
@Controller
@RequestMapping("/statistic/pm")
public class StatisticPMController extends BaseController{

    /**
     * 前缀
     */
    private String prefix = "statistic/pm";

    /**
     * 统计服务
     */
    @Autowired
    private IStatisticService statisticService;


    /**
     * 统计页面
     */
    @RequiresPermissions("statistic:pm:view")
    @GetMapping()
    public String list()
    {
        return prefix + "/pm";
    }


    /**
     * 根据Bu统计饼图
     */
    @RequiresPermissions("statistic:pm:view")
    @PostMapping("/list/listByPie")
    @ResponseBody
    public EchartsPieVO listByPie()
    {
        EchartsPieVO res = new EchartsPieVO();
        List<StatisDept>  list = statisticService.selectCountPMStatisByProjectRole(ShiroUtils.getUserId());
        List<String> data = new ArrayList<String>();
        List<SerizeData> serizeData = new ArrayList<SerizeData>();
        res.setData(data);
        res.setSerizeData(serizeData);
        for(int i =0;i<list.size();i++){
            StatisDept sd = list.get(i);
            data.add(sd.getProjectRole());
            SerizeData sdata = new SerizeData();
            sdata.setName(sd.getProjectRole());
            sdata.setValue(sd.getNum());
            serizeData.add(sdata);
        }
        return res;
    }


    /**
     * PM统计柱状图
     */
    @RequiresPermissions("statistic:pm:view")
    @PostMapping("/list/listByBar")
    @ResponseBody
    public EchartsPieVO listByBgBar(String depts)
    {
        EchartsPieVO res = new EchartsPieVO();
        List<StatisDept>  list = statisticService.selectCountPMStatisByProjectRole(ShiroUtils.getUserId());
        List<String> data = new ArrayList<String>();
        List<SerizeData> serizeData = new ArrayList<SerizeData>();
        res.setData(data);
        res.setSerizeData(serizeData);
        for(int i =0;i<list.size();i++){
            StatisDept sd = list.get(i);
            data.add(sd.getProjectRole());
            SerizeData sdata = new SerizeData();
            sdata.setName(sd.getProjectRole());
            sdata.setValue(sd.getNum());
            serizeData.add(sdata);
        }
        return res;
    }

    /**
     * PM统计柱状图
     */
    @RequiresPermissions("statistic:pm:view")
    @PostMapping("/list/listByLine")
    @ResponseBody
    public Map<String,Object> listByBgLine(String depts)
    {
        Map<String,Object> res = new HashMap<String,Object>();
        List<StatisDept>  list = statisticService.selectCountPMStatisByDateInfo(ShiroUtils.getUserId());
        List<String> data = new ArrayList<String>();
        List<Integer> serizeData = new ArrayList<Integer>();
        for(int i =0;i<list.size();i++){
            StatisDept sd = list.get(i);
            data.add(sd.getDateInfo());
            serizeData.add(sd.getNum());
        }
        res.put("data",data);
        res.put("serizeData",serizeData);
        return res;
    }
}
